import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:ichinesereader/controller/user.dart';
import 'package:ichinesereader/themes/appTheme.dart';
import 'package:toggle_switch/toggle_switch.dart';
import 'package:ichinesereader/utils/log.dart';

class ParentAppDrawer extends StatelessWidget {
  ParentAppDrawer({Key? key}) : super(key: key);
  final UserController _userController = Get.find();
  final box = Hive.box('appconfig');

  @override
  Widget build(BuildContext context) {
    return Drawer(
      child: SingleChildScrollView(
        scrollDirection: Axis.vertical,
        primary: false,
        child: Column(
          children: <Widget>[
            SizedBox(height: 50),
            ListTile(
              selected: Get.currentRoute == '/parent/home',
              selectedTileColor: Get.isDarkMode
                  ? Get.theme.primaryColor
                  : Get.theme.primaryColorDark,
              leading: Icon(
                Icons.home,
                color: Get.currentRoute == '/parent/home'
                    ? AppTheme.colors.drawerItemColor
                    : AppTheme.colors.drawerItemSelectedColor,
                size: 30.0,
              ),
              title: Text(
                "Home".tr,
                style: Theme.of(context).textTheme.displayLarge?.copyWith(
                      color: Get.currentRoute == '/parent/home'
                          ? AppTheme.colors.drawerItemColor
                          : AppTheme.colors.drawerItemSelectedColor,
                      fontSize: 16,
                      fontFamily: 'Montserrat',
                    ),
              ),
              onTap: () {
                if (GetPlatform.isWeb) {
                  Get.offAllNamed('/parent/home');
                } else {
                  Get.offAllNamed('/parent/home');
                }
              },
            ),
            Divider(
              color: Theme.of(context).primaryColorLight,
            ),
            ListTile(
              selected: Get.currentRoute == '/parent/reports',
              selectedTileColor: Get.isDarkMode
                  ? Get.theme.primaryColor
                  : Get.theme.primaryColorDark,
              leading: Icon(
                Icons.bar_chart_rounded,
                color: Get.currentRoute == '/parent/reports'
                    ? AppTheme.colors.drawerItemColor
                    : AppTheme.colors.drawerItemSelectedColor,
                size: 30.0,
              ),
              title: Text(
                "Reports".tr,
                style: Theme.of(context).textTheme.displayLarge?.copyWith(
                      color: Get.currentRoute == '/parent/reports'
                          ? AppTheme.colors.drawerItemColor
                          : AppTheme.colors.drawerItemSelectedColor,
                      fontSize: 16,
                      fontFamily: 'Montserrat',
                    ),
              ),
              onTap: () {
                if (GetPlatform.isWeb) {
                  Get.toNamed('/parent/reports');
                  // launchInWebViewWithJavaScript(
                  //     '${Constants.BaseURL}icr/teacher/report');
                } else
                  Get.offAllNamed('/parent/reports');
              },
            ),
            Divider(
              color: Theme.of(context).primaryColorLight,
            ),
            ListTile(
              selected: Get.currentRoute == '/parent/leveledreadings',
              selectedTileColor: Get.isDarkMode
                  ? Get.theme.primaryColor
                  : Get.theme.primaryColorDark,
              leading: Icon(
                Icons.local_library,
                color: Get.currentRoute == '/parent/leveledreadings'
                    ? AppTheme.colors.drawerItemColor
                    : AppTheme.colors.drawerItemSelectedColor,
                size: 30.0,
              ),
              title: Text(
                "Leveled Readings".tr,
                style: Theme.of(context).textTheme.displayLarge?.copyWith(
                      color: Get.currentRoute == '/parent/leveledreadings'
                          ? AppTheme.colors.drawerItemColor
                          : AppTheme.colors.drawerItemSelectedColor,
                      fontSize: 16,
                      fontFamily: 'Montserrat',
                    ),
              ),
              onTap: () {
                if (GetPlatform.isWeb) {
                  Get.toNamed('/parent/leveledreadings');
                } else {
                  Get.offAllNamed('/parent/leveledreadings');
                }
              },
            ),
            Divider(
              color: Theme.of(context).primaryColorLight,
            ),
            ListTile(
              selected: Get.currentRoute == '/parent/myfavorites',
              selectedTileColor: Get.isDarkMode
                  ? Get.theme.primaryColor
                  : Get.theme.primaryColorDark,
              leading: Icon(
                Icons.local_library,
                color: Get.currentRoute == '/parent/myfavorites'
                    ? AppTheme.colors.drawerItemColor
                    : AppTheme.colors.drawerItemSelectedColor,
                size: 30.0,
              ),
              title: Text(
                "Child's Favorites".tr,
                style: Theme.of(context).textTheme.displayLarge?.copyWith(
                      color: Get.currentRoute == '/parent/myfavorites'
                          ? AppTheme.colors.drawerItemColor
                          : AppTheme.colors.drawerItemSelectedColor,
                      fontSize: 16,
                      fontFamily: 'Montserrat',
                    ),
              ),
              onTap: () {
                if (GetPlatform.isWeb) {
                  Get.toNamed('/parent/myfavorites');
                } else {
                  Get.offAllNamed('/parent/myfavorites');
                }
              },
            ),
            Divider(
              color: Theme.of(context).primaryColorLight,
            ),
            SizedBox(height: 20),
            ToggleSwitch(
              minWidth: 120.0,
              cornerRadius: 0.0,
              activeBgColors: [
                [Color(0xff0085cc)],
              ],
              activeFgColor: Color(0xffd8ffff),
              inactiveBgColor: Color(0xff666666),
              inactiveFgColor: Color(0xffEEEEEE),
              totalSwitches: 2,
              labels: ['LIGHT', 'DARK'],
              onToggle: (index) {
                Log.debug('switched to: $index');
                index == 0
                    ? _userController.changeTheme(isDarkMode: false)
                    : _userController.changeTheme(isDarkMode: true);
              },
            ),
          ],
        ),
      ),
    );
  }
}
